package com.code.generation.utils;

import com.code.generation.constant.FileConstants;
import com.code.generation.constant.TempConstants;
import org.springframework.util.ResourceUtils;

import java.io.FileNotFoundException;

/**
 * @ProjectName: codegeneration
 * @Package: com.code.generation.utils
 * @Description:
 * @Author: DongJW
 * @CreateDate: 2020/11/29 11:33
 * @Version: 1.0
 */
public class TempUtils {

    public static String getTemplateDir(String type) throws FileNotFoundException {
        String templateDir =null;
        String classpath = ResourceUtils.getURL(FileConstants.CLASSPATH).getPath();
        if (classpath.startsWith(FileConstants.SEPARATOR)){
            classpath = classpath.replaceFirst(FileConstants.SEPARATOR, FileConstants.EMPTY);
        }
        if (TempConstants.TEMPLATE_TYPE_ALL.equals(type)){
            templateDir = classpath+TempConstants.TEMPLATE_DIR_ALL;
        }else if (TempConstants.TEMPLATE_TYPE_HTML.equals(type)){
            templateDir = classpath+TempConstants.TEMPLATE_DIR_HTML;
        }else if (TempConstants.TEMPLATE_TYPE_JAVA.equals(type)){
            templateDir = classpath+TempConstants.TEMPLATE_DIR_JAVA;
        }
        return templateDir;
    }
}
